'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    const { INTEGER, STRING, DATE } = Sequelize;
    
    await queryInterface.createTable('brands', {
      id: {
        type: INTEGER,
        primaryKey: true,
        autoIncrement: true
      },
      name: {
        type: STRING(100),
        allowNull: false,
        unique: true,
        comment: '品牌名称'
      },
      description: {
        type: STRING(500),
        comment: '品牌描述'
      },
      status: {
        type: STRING(20),
        defaultValue: 'active',
        comment: '品牌状态: active-启用, inactive-禁用'
      },
      created_at: {
        type: DATE,
        allowNull: false,
        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
      },
      updated_at: {
        type: DATE,
        allowNull: false,
        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
      }
    });
    
    // 添加索引
    await queryInterface.addIndex('brands', ['name'], {
      name: 'brands_idx_name',
      unique: true
    });
    await queryInterface.addIndex('brands', ['status'], {
      name: 'brands_idx_status',
      unique: false
    });
  },

  down: async (queryInterface, Sequelize) => {
    // 删除索引
    await queryInterface.removeIndex('brands', 'brands_idx_name');
    await queryInterface.removeIndex('brands', 'brands_idx_status');
    
    await queryInterface.dropTable('brands');
  }
};